-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setup HOME environment when using --userns=keep-id #8013
Conversation
if MountExists(c.config.Spec.Mounts, u.HomeDir) { | ||
homeDir = u.HomeDir | ||
hDir := u.HomeDir | ||
for hDir != "/" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u.HomeDir is a string no?
for hDir != "/" { | |
if hDir != "/" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is attempting to walk up the directories to check if their is a mountpoint from the host that covers this directory.
For example if my homedir was /home/engineering/dwalsh.
I want to check if
/home/engineering/dwalsh
/home/engineering
/home
Is mounted into the container, if yes then I can use /home/engineering/dwalsh as the homedir, rather then CWD.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we want to look through the directories.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this is really wanted - when I originally wrote this, I wanted it to be specific to ensure that we didn't leak information about the user on the host into the container unless they were explicitly mounting their home
homeDir = u.HomeDir | ||
break | ||
} | ||
hDir = filepath.Dir(hDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
me thinks
hDir = filepath.Dir(hDir) | |
homeDir = filepath.Dir(hDir) |
hDir doesn't seem to be referred to after this line otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If hDir is volume mounted into the container then
+ homeDir = u.HomeDir
+ break
Is executed which sets the homeDir to the directory from the host as opposed to the CWD.
test/e2e/toolbox_test.go
Outdated
|
||
currentUser, err := user.Current() | ||
Expect(err).To(BeNil()) | ||
session = podmanTest.Podman([]string{"run", "--name", "-v", fmt.Sprintf("%s:%s:Z", currentUser.HomeDir, currentUser.HomeDir), "test", "--userns=keep-id", fedoraToolbox, "sh", "-c", "echo $HOME"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked at the CI failures, but I'm guessing that --name -v
is not going to work well
There's a bug somewhere, I don't have time right now to delve into it: $ ./bin/podman run --userns=keep-id quay.io/libpod/testimage:20200929 printenv HOME
/home/podman (my username on this system is 'esm', not 'podman'. There is a valid UPDATE: I think this goes deeper than just $HOME: $ ./bin/podman run -it -v /home/esm --userns=keep-id alpine sh
~ $ pwd
/
~$ tail -1 /etc/passwd
esm:*:14904:14904:esm:/:/bin/sh
~$ ls -l /home
total 4
drwxr-xr-x 2 esm esm 4096 Oct 14 16:45 esm |
@edsantiago Sadly I don't think I can handle just creating the internal /home/dir. |
I was just trying that, and it works. I was curious why plain |
I am not sure of what the correct thing to do is. It would simplify the code quite a bit. |
Setting $HOME to point at an non existing homedir, might be problematic. |
Agreed. My concern is: image has workdir. User runs container with |
Yuk - failure looks horrible, but I can't see how it could be related to your PR. Am restarting.
Will assume that my flake-monitor will gather it up, add it to the list, and I'll eventually notice if this one is a common one. |
Currently the HOME environment is set to /root if the user does not override it. Also walk the parent directories of users homedir to see if it is volume mounted into the container, if yes, then set it correctly. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
@edsantiago I now cover your case as well.
|
That looks really good, thank you. I've got tests in the works, will submit PR as soon as yours merges. |
More tests.
|
- run --userns=keep-id: confirm that $HOME gets set (containers#8013) - inspect: confirm that JSON output is a sane number of lines (10 or more), not an unreadable one-liner (containers#8011 and containers#8021). Do so with image, pod, network, volume because the code paths might be different. - cgroups: confirm that 'run' preserves cgroup manager (containers#7970) - sdnotify: reenable tests, and hope CI doesn't hang. This test was disabled on August 18 because CI jobs were hanging and timing out. My suspicion was that it was containers#7316, which in turn seems to have hinged on conmon containers#182. The latter was merged on Sep 16, so let's cross our fingers and see what happens. Also: remove inaccurate warning from a networking test. And, wow, fix is_cgroupsv2(), it has never actually worked. Signed-off-by: Ed Santiago <santiago@redhat.com>
@rhatdan looks like you're still on the bucking bronco of a test system. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@giuseppe @saschagrunert PTAL and merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: rhatdan, saschagrunert The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Currently the HOME environment is set to /root if
the user does not override it.
Also walk the parent directories of users homedir
to see if it is volume mounted into the container,
if yes, then set it correctly.
Fixes: #8004
Signed-off-by: Daniel J Walsh dwalsh@redhat.com